//获取应用实例
var app = getApp();
Page({
    data: {
        //处理订单
        orderStatusDoingText:"处理订单",
        orderStatusFinishText:"订单完成",
        orderStatusOneClass: "icon_doing",
        orderStatusThreeClass: "icon_end",
        orderStatusTwoClass: "icon_end",
        orderStatusOneTextClass: "",
        orderStatusTwoTextClass: "",
        orderStatusThreeTextClass: "",
        orderStatusExplainClass: "icon_order_succeed",
        orderStatusLineOneClass: "",
        orderStatusLineTwoClass: "",
        orderStatusLineThreeClass: "",
        isShowPage:false
    },
    onLoad: function (option) {
        var orderId = option.orderId;
        // var orderId = "201710261279640293";
        var pageObj = this;
        var opt = {
            url: app.globalData.host+"/wx/an/detail.ajax",
            data: {'orderId':orderId},
            sucFn:function (result) {
                pageObj.setData({
                    isShowPage:true,
                    statusName:result.body.statusName,
                    statusDescDetail:result.body.statusDescDetail,

                    isYueS:app.isYueS(result.body.carNumber.substring(0,2)),
                    doc:result.body.docs.split("\\n").join("\n"),
                    serviceFeeDesc:result.body.serviceFeeDesc,
                    serviceFee:result.body.serviceFee,
                    carNumber:result.body.carNumber,
                    carCode:result.body.carCode,
                    cardName:result.body.cardName,
                    cardNum:result.body.cardNum,
                    telephone:result.body.telephone,
                    cardPicture:result.body.cardPicture,
                    policyPicture:result.body.policyPicture,

                    "address.contactName":result.body.address.contactName,
                    "address.cellNum":result.body.address.cellNum,
                    "address.fullAddr":result.body.address.fullAddr,

                    orderId:result.body.orderId,
                    payNo:result.body.payNo,
                    progressTitle:result.body.progressName,
                    progressTime:app.toYMDHMSDate(result.body.progressTime),
                    createTime:app.toYMDHMSDate(result.body.createTime),
                    completeTimeText:result.body.status==8?"完成时间":"关闭时间",
                    completeTime:result.body.completeTime?app.toYMDHMSDate(result.body.completeTime):null,
                    chargeTime:result.body.payTime?app.toYMDHMSDate(result.body.payTime):null,
                    needInvoice:result.body.needInvoice
                });
                switch (result.body.status) {
                    case 2://支付成功
                        pageObj.setData({
                            orderStatusDoingText: "处理订单",
                            orderStatusFinishText: "订单完成",
                            orderStatusOneClass: "icon_complete",
                            orderStatusTwoClass: "icon_doing",
                            orderStatusThreeClass: "",
                            orderStatusLineOneClass: "bg-colo-00B488",
                            orderStatusLineTwoClass: "bg-colo-00B488",
                            orderStatusLineThreeClass: "",
                            orderStatusOneTextClass: "",
                            orderStatusTwoTextClass: "state_color_blue",
                            orderStatusThreeTextClass: "",
                            orderStatusExplainClass: "icon_order_succeed",
                            orderStatusLineColour: "bg-color_blue",
                            orderStatusExplainTextClass: "color-00b488"
                        });
                        break;
                    case 3://退单申请中
                        pageObj.setData({
                            orderStatusDoingText: "办理失败",
                            orderStatusFinishText: "订单完成",
                            orderStatusOneClass: "icon_complete",
                            orderStatusTwoClass: "icon_failing",
                            orderStatusThreeClass: "",
                            orderStatusLineOneClass: "bg-colo-00B488",
                            orderStatusLineTwoClass: "bg-colo-00B488",
                            orderStatusLineThreeClass: "",
                            orderStatusOneTextClass: "",
                            orderStatusTwoTextClass: "state_color_red",
                            orderStatusThreeTextClass: "",
                            orderStatusExplainClass: "icon_oeder_close_off",
                            orderStatusLineColour: "bg-color",
                            orderStatusExplainTextClass: "color-e64340"
                        });
                        break;
                    case 4://订单关闭
                        pageObj.setData({
                            orderStatusDoingText:"办理失败",
                            orderStatusFinishText:"订单关闭",
                            orderStatusOneClass: "icon_complete",
                            orderStatusTwoClass: "icon_fail",
                            orderStatusThreeClass: "icon_failing",
                            orderStatusLineOneClass: "bg-color-red",
                            orderStatusLineTwoClass: "bg-color-red",
                            orderStatusLineThreeClass: "bg-color-red",
                            orderStatusOneTextClass: "",
                            orderStatusTwoTextClass: "",
                            orderStatusThreeTextClass: "",
                            orderStatusExplainClass: "icon_oeder_close_off",
                            orderStatusLineColour: "bg-color",
                            orderStatusExplainTextClass: "color-e64340"
                        });
                        break;
                    case 8://已完成
                        pageObj.setData({
                            orderStatusDoingText: "处理订单",
                            orderStatusFinishText: "订单完成",
                            orderStatusOneClass: "icon_complete",
                            orderStatusTwoClass: "icon_complete",
                            orderStatusThreeClass: "icon_doing",
                            orderStatusLineOneClass: "bg-colo-00B488",
                            orderStatusLineTwoClass: "bg-colo-00B488",
                            orderStatusLineThreeClass: "bg-colo-00B488",
                            orderStatusOneTextClass: "",
                            orderStatusTwoTextClass: "state_color_blue",
                            orderStatusThreeTextClass: "state_color_blue",
                            orderStatusExplainClass: "icon_order_succeed",
                            orderStatusLineColour: "bg-color_blue",
                            orderStatusExplainTextClass: "color-00b488"
                        });
                        break;
                    default://其他
                        break;
                }
            }
        };
        app.ajax(opt);

    },
    onHide:function () {
        app.removeStorageSync(app.globalData.cacheOrderResKey);
    },
    viewUploadImgTap:function (e) {
        var uploadImgSrc = e.currentTarget.dataset.src;
        var opt = {
            urls:[uploadImgSrc],
            success:function (res) {
                console.log(res);
            }
        };
        app.previewImage(opt)
    },
    progressTap:function(e){
        var orderId = e.target.dataset.id;
        app.navigateTo({
            url: '../progress/progress?orderId='+orderId
        });
    },
    formatCardNum:function (cardNum) {
        return cardNum.substr(0, 6) + "******" + cardNum.substr(cardNum.length - 2, cardNum.length);
    },
    formatTel:function (tel) {
        return tel;
        // return tel.substr(0, 3) + "****" + tel.substr(tel.length - 4, tel.length);
    }
});
